package com.heima.article.listen;

import com.heima.article.service.ApArticleService;
import com.heima.model.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PublishArticleListener {

    @Autowired
    private ApArticleService apArticleService;

    @RabbitListener(queuesToDeclare = @Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE))
    public void publishArticle(String newsId){
        log.info("成功监听到文章ID{}",newsId);
        apArticleService.publishArticle(Integer.valueOf(newsId));
    }
}
